# Define the data
df <- tribble(
  ~pre_registered, ~new, ~justification, ~location,
  # Primary Outcomes
  "Election Integrity", "Support for Democracy", "Conceptual distinction", "Table 1",
  "", "Trust in Elections", "---", "Table 1",
  "Intolerance", "Partisan Animosity", "Conceptual distinction", "Table A4",
  "", "Ethnic Animosity", "---", "Table A4",
  "Reasons for Victory/Loss", "---", "---", "Table A4",
  "Institutional Trust", "---", "---", "Table A4",
  # Heterogeneity Analyses
  "Campaign expenditures", "---", "---", "Figure 2",
  "RWA Index", "---", "---", "Figure 2",
  "Neuroticism", "---", "---", "Figure 2",
  "Expectations of victory", "---", "---", "Figure 2",
  "Internal motivation", "---", "---", "Figure 2",
  "Time spent campaigning", "---", "---", "Figure 2",
  "---", "Age", "Peer-feedback", "Figure 2",
  "---", "Gender", "Peer-feedback", "Figure 2",
  "---", "Party-type", "Peer-feedback", "Figure 2",
  "---", "Incumbency", "Peer-feedback", "Figure 2",
  "---", "Ethnicity/Religion", "Peer-feedback", "Figure 2"
)

# Create the table
df %>%
  kbl(
    "latex",
    booktabs = TRUE,
    escape = FALSE,
    longtable = TRUE,
    col.names = c("Pre-Registered Variables", "New Variables", 
                  "Justification for Deviation", "Location of Analysis"),
    caption = "\\label{tab:pap}Pre-Registered vs New Variables Analysis",
    align = "llll",
  ) %>%
  add_header_above(c(" " = 4)) %>%
  pack_rows("Primary Outcomes", 1, 2, bold = TRUE, latex_gap_space = "0.5em") %>%
  pack_rows("Secondary Outcomes", 3, 6, bold = TRUE, latex_gap_space = "0.5em") %>%
  pack_rows("Heterogeneity Analyses", 7, 17, bold = TRUE, latex_gap_space = "0.5em") %>%
  kable_styling(
    font_size = 9,
    latex_options = c("scale_down", "hold_position", "striped")
  ) %>%
  cat(., file = "./outputs/tables/table_a1.tex")

